var audio = sm("do_Audio");//音频播放与录制
var imHelper = require("helper/im");
var frameR = ui("frameR");
var rootView = ui("$");
var isPlaying = false;//是否正在播放
rootView.setMapping({
	"voiceLen.tag" : "voiceLen",
	"voiceLen.text" : "text",
	"imgMyLogo.source" : "logo",
	"layoutVoice.tag" : "voice"
});
frameR.startGif("source://image/im/audioR.gif",-1);
ui("layoutVoice").on("touch", function(data, e) {
	if(isPlaying){//如果正在播放，再点击就停止
		stopAudio();
	}else{
		playAudio();
	}
})

//当播放完毕
audio.on("playFinished", function(data) {
	isPlaying = false;
	frameR.startGif("source://image/im/audioR.gif",-1);
});

function playAudio(){
	var voiceFile = ui("layoutVoice").tag;
	//deviceone.print("语音remotePath:"+voiceFile);
	if(voiceFile!=null){
		imHelper.loadAudioFile(voiceFile,function(localPath){
			isPlaying = true;
			frameR.startGif("source://image/im/audioRing.gif",-1);
			audio.play(localPath);
		})
	}
}

function stopAudio(){
	isPlaying = false;
	audio.stop();
	frameR.startGif("source://image/im/audioR.gif",-1);
}